<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="schemeList" @selection-change="handleSelectionChange">
      <el-table-column label="等级编号" align="center" prop="tegrLevelCode" :show-overflow-tooltip="true" />
      <el-table-column label="等级名称" align="center" prop="tegrLevelName" :show-overflow-tooltip="true"/>
      <el-table-column label="等级分数" align="center" prop="tegrLevelScore" :show-overflow-tooltip="true">
        <template slot-scope="scope">
            [{{scope.row.beginScoreArea}} ~ {{scope.row.endScoreArea}})
        </template>
      </el-table-column>
        
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" circle type="danger" icon="el-icon-delete"
              @click="handleDelete(scope.row)" />
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="级别标签" prop="tegrLevelName">
          <el-input type="input" v-model="form.tegrLevelName" placeholder="请输入级别标签"></el-input>
        </el-form-item>      
        <el-form-item label="分数" prop="tegrLevelScore">
          <el-input type="input" v-model="form.tegrLevelScore" placeholder="请输入分数" />
        </el-form-item>
        <el-input type="hidden" v-model="form.tescId"/>
        <table>
          
        </table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>

</template>

<script>
import { listEvResultType, delEvResultType, addEvResultType} from "@/api/teacher/evaluation/scheme_result_type";
import { Footer } from "element-ui";


export default {
  name: "scheme",
  data() {
    
    return {
      options: [],
      //方案id
      tescId: undefined,
      tescIds: 0,
      // 遮罩层
      loading: true,
      loadingItem: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 表格数据
      schemeList: [],
      // 弹出层标题
      title: "",
      titleBizName: "考评结果级别",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        type: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        tegrLevelScore: [
          { required: true, message: "组别分数不能为空", trigger: "blur" }
        ],
        tegrLevelName: [
          { required: true, message: "级别标签不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.tescId = this.$route.query.tescId;
    this.getList();
  },
  methods: {
    /** 表格数据列表 */
    getList() {
      this.loading = true;
      listEvResultType(this.tescId).then(response => {
        this.schemeList = response.data;
        this.total = response.data.total;
        this.loading = false;
      }
      );
    },
    // 字典状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        "tescId": this.tescId,
				"tegrLevelScore": undefined,
				"tegrLevelName": undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加" + this.titleBizName;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          addEvResultType(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认等级编号为"' + row.tegrLevelCode + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delEvResultType(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(function () { });
    }
  }
};
</script>
<style>
.hint {
  font-size: 10px;
  height: 10px;
  color: rgb(253, 93, 93);
}
</style>
